//栈的类
function Stack(){
    //基于数组实现
    this.items = [];
    //栈的方法push、pop、isEmpty、peek、size、toString
    Stack.prototype.push=function(element){
        this.items.push(element);
        return true
    };
    Stack.prototype.pop=function(){
        return this.items.pop()
    };
    Stack.prototype.isEmpty = function () { 
        return  this.items.length == 0
     };
    Stack.prototype.peek=function(){
         //查询栈顶元素，不做其他操作
         return this.items[this.items.length-1]
     };
    Stack.prototype.size = function () { 
         return this.items.length
      };
    Stack.prototype.toString = function () { 
          let resStr = '';
          this.items.forEach((item,index)=>{
              resStr +=item + ' ';
          });
          return resStr
       }

};
